//
//  MQCustomInfoViewController.m
//  meiquan
//
//  Created by hejingjin on 2017/10/28.
//  Copyright © 2017年 mq. All rights reserved.
//

#import "MQCustomInfoViewController.h"

#import "MQCustomdetailinfoview.h"
#import "MQBaseUserInfoModel.h"
#import "ZHPickView.h"
#import "MQAddressView.h"

#import "NSString+Extension.h"

#import "MQadviews.h"
#import "MQAdmodels.h"


@interface MQCustomInfoViewController ()<ZHPickViewDelegate,UIPickerViewDataSource, UIPickerViewDelegate,UITextFieldDelegate>
{
    NSInteger _provinceIndex;   // 省份选择 记录
    NSInteger _cityIndex;       // 市选择 记录
    NSInteger _districtIndex;   // 区选择 记录
}


@property(nonatomic,strong)UIScrollView *bgscrollview;
@property(nonatomic,strong)MQCustomdetailinfoview *custominfoview;


@property(nonatomic,strong)NSArray *kehuleixing;
@property(nonatomic,strong)NSArray *goumaili;
@property(nonatomic,strong)NSArray *bapyangzhichu;
@property(nonatomic,strong)NSArray *kehuguanxi;
@property(nonatomic,strong)NSArray *kehulaiyuan;
@property(nonatomic,strong)NSArray *dailishuxin;
@property(nonatomic,strong)NSArray *chongshishiye;
@property(nonatomic,strong)NSArray *guimo;
@property(nonatomic,strong)NSArray *shifouguanzhu;
@property(nonatomic,strong)NSArray *sexarray;

@property(nonatomic,strong)NSMutableArray *dataarray;


@property(nonatomic,strong)MQadviews *adviews;

@property(nonatomic,strong)MQAdmodels *admodels;

@property(nonatomic,strong)ZHPickView *sexpick;
@property(nonatomic,strong)ZHPickView *kehulexingpick;
@property(nonatomic,strong)ZHPickView *goumaipic;
@property(nonatomic,strong)ZHPickView *bapyangzhichupick;
@property(nonatomic,strong)ZHPickView *kehuguanxipic;
@property(nonatomic,strong)ZHPickView *kehulaiyuanpic;
@property(nonatomic,strong)ZHPickView *dailishuxinpic;
@property(nonatomic,strong)ZHPickView *chongshishiyepic;
@property(nonatomic,strong)ZHPickView *guimopic;
@property(nonatomic,strong)ZHPickView *shifouguanzhupic;
@property(nonatomic,strong)MQAddressView *adderssview;
@property(nonatomic,strong)ZHPickView *jianzhipic;
@property(nonatomic,strong)ZHPickView *huazhuangpingpic;
@property(nonatomic,strong)ZHPickView *birthdaypic;

@property(nonatomic,strong)NSArray *addarray;
@end

@implementation MQCustomInfoViewController


-(void)cancelbuttonPressed:(UIButton *)semnder{
//     [self.view bringSubviewToFront:_adderssview];
    [self.view sendSubviewToBack:_adderssview];
     _provinceIndex = _cityIndex = _districtIndex = 0;
    _adderssview.hidden = YES;
    [_adderssview.pickerviews reloadAllComponents];
}

-(void)makesurebuttonPressed:(UIButton *)sender{
    NSString *address = [NSString stringWithFormat:@"%@ %@ %@", self.addarray[_provinceIndex][@"name"], self.addarray[_provinceIndex][@"list"][_cityIndex][@"name"], self.addarray[_provinceIndex][@"list"][_cityIndex][@"list"][_districtIndex][@"name"]];
//    NSLog(@"%@",address);
    _adderssview.hidden = YES;
    _custominfoview.adderLabel.text = address;
     [self.view sendSubviewToBack:_adderssview];
}


#pragma mark - UIPicker Delegate
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView {
    return 3;
}

- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component {
    if(component == 0){
        return self.addarray.count;
    }
    else if (component == 1){
        return [self.addarray[_provinceIndex][@"list"] count];
    }
    else{
        return [self.addarray[_provinceIndex][@"list"][_cityIndex][@"list"] count];
    }
}

- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component {
    if(component == 0){
        return self.addarray[row][@"name"];
    }
    else if (component == 1){
        return self.addarray[_provinceIndex][@"list"][row][@"name"];
    }
    else{
        return self.addarray[_provinceIndex][@"list"][_cityIndex][@"list"][row][@"name"];
    }
}

- (CGFloat)pickerView:(UIPickerView *)pickerView widthForComponent:(NSInteger)component {
    
    return BSTScreenW/3;
}

- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component {
    if(component == 0){
        _provinceIndex = row;
        _cityIndex = 0;
        _districtIndex = 0;
        [self.adderssview.pickerviews reloadComponent:1];
        [self.adderssview.pickerviews reloadComponent:2];
    }
    else if (component == 1){
        _cityIndex = row;
        _districtIndex = 0;
        [self.adderssview.pickerviews reloadComponent:2];
    }
    else{
        _districtIndex = row;
    }
    // 重置当前选中项
    [self resetPickerSelectRow];
}
-(void)resetPickerSelectRow
{
    [self.adderssview.pickerviews selectRow:_provinceIndex inComponent:0 animated:YES];
    [self.adderssview.pickerviews selectRow:_cityIndex inComponent:1 animated:YES];
    [self.adderssview.pickerviews selectRow:_districtIndex inComponent:2 animated:YES];
}

- (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view{
    UILabel* pickerLabel = (UILabel*)view;
    if (!pickerLabel){
        pickerLabel = [[UILabel alloc] init];
        // Setup label properties - frame, font, colors etc
        //adjustsFontSizeToFitWidth property to YES
        pickerLabel.minimumScaleFactor = 8.;
        pickerLabel.adjustsFontSizeToFitWidth = YES;
        [pickerLabel setTextAlignment:NSTextAlignmentCenter];
        [pickerLabel setFont:[UIFont boldSystemFontOfSize:15]];
    }
    // Fill the label text here
    pickerLabel.text = [self pickerView:pickerView titleForRow:row forComponent:component];
    return pickerLabel;
}

-(void)getaddata{
    
    NSArray *array = @[@"page1",@"@page2",@"page3"];
    int x = arc4random() % 3;
    
    MQBaseUserInfoModel *userinfo = [MQBaseUserInfoModel shareInstant];
    [userinfo loadUserinfoFromSadeBox];
    NSMutableDictionary *param = [NSMutableDictionary dictionary];
    
    [param setValue:userinfo.userId forKey:@"userId"];
    [param setValue:array[x] forKey:@"code"];
    [param setValue:@"page1" forKey:@"code"];
    
    [MQRequestTools POSTWithMethod:adv_index params:param success:^(id json) {
        
        NSDictionary *dic = [json valueForKey:@"data"];
        _admodels = [MQAdmodels mj_objectWithKeyValues:dic];
        if (_admodels.advId) {
            [_adviews.adimageviews sd_setImageWithURL:[NSURL URLWithString:_admodels.pic] placeholderImage:[UIImage imageNamed:@""]];
        }else{
            _adviews.bst_height = 0;
            _bgscrollview.bst_y = NAVHEIGHT;
          
        }
        
        
        UITapGestureRecognizer *tapGesturRecognizer=[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapAction:)];
        [_adviews addGestureRecognizer:tapGesturRecognizer];
        
    } failure:^(NSError *error) {
        
    }];
    
    
}

-(void)tapAction:(UITapGestureRecognizer *)obj{
    NSLog(@"%@",_admodels.url);
    MQAdDetailViewController *advc = [[MQAdDetailViewController alloc] init];
    advc.url = _admodels.url;
     advc.type = _admodels.type;
    [self.navigationController pushViewController:advc animated:YES];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    
    self.automaticallyAdjustsScrollViewInsets = NO;
    _provinceIndex = _cityIndex = _districtIndex = 0;

    NSString *dataFilePath = [[NSBundle mainBundle] pathForResource:@"region" ofType:@"json"];
    NSData *data = [NSData dataWithContentsOfFile:dataFilePath];
    _addarray = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingAllowFragments error:nil];
    self.title = @"客户资料";
    
    _adderssview = [MQAddressView loadaddressviews];
    _adderssview.bst_x = 0;
    _adderssview.bst_height = BSTScreenH * 0.3;
    _adderssview.bst_y = BSTScreenH * 0.7;
    _adderssview.bst_width = BSTScreenW;
    _adderssview.pickerviews.delegate = self;
    _adderssview.pickerviews.dataSource = self;
    [_adderssview.cancelbutton addTarget:self action:@selector(cancelbuttonPressed:) forControlEvents:UIControlEventTouchUpInside];
    [_adderssview.makesurebutton addTarget:self action:@selector(makesurebuttonPressed:) forControlEvents:UIControlEventTouchUpInside];
    
    [self.view addSubview:_adderssview];
    
    
    NSDate *currentdate = [NSDate new];
    
    _birthdaypic = [[ZHPickView alloc] initDatePickWithDate:currentdate datePickerMode:UIDatePickerModeDate isHaveNavControler:NO];
    _birthdaypic.tag = 1012;
    _birthdaypic.delegate = self;

    
    _dataarray = [NSMutableArray array];
    
    _sexarray = @[@"男",@"女"];
    _sexpick = [[ZHPickView alloc] initPickviewWithArray:_sexarray isHaveNavControler:NO];
//    _sexpick  = [[ZHPickView alloc]initPickviewWithPlistName:@"region" isHaveNavControler:NO];
    _sexpick.tag = 1000;
    _sexpick.delegate = self;
    
    
    _kehuleixing = @[@"潜在客户",@"零售客户",@"入门理商",@"中级代理",@"高级代理",@"失效客户",@"失效代理"];
    
    _kehulexingpick = [[ZHPickView alloc] initPickviewWithArray:_kehuleixing isHaveNavControler:NO];
    _kehulexingpick.tag = 1001;
    _kehulexingpick.delegate = self;
    
    _goumaili = @[@"低",@"中",@"高"];
    _goumaipic = [[ZHPickView alloc] initPickviewWithArray:_goumaili isHaveNavControler:NO];
    _goumaipic.tag = 1002;
    _goumaipic.delegate = self;
    
    _jianzhipic =[[ZHPickView alloc] initPickviewWithArray:_goumaili isHaveNavControler:NO];
    _goumaipic.tag = 1010;
    _goumaipic.delegate = self;
    
    _huazhuangpingpic =[[ZHPickView alloc] initPickviewWithArray:_goumaili isHaveNavControler:NO];
    _huazhuangpingpic.tag = 1011;
    _huazhuangpingpic.delegate = self;
    
    _bapyangzhichu = @[@"低",@"中",@"高",@"特别高"];
    _bapyangzhichupick = [[ZHPickView alloc] initPickviewWithArray:_bapyangzhichu isHaveNavControler:NO];
    _bapyangzhichupick.tag = 1003;
    _bapyangzhichupick.delegate = self;

    _kehuguanxi = @[@"无联系",@"少有联系",@"经常联系",@"频繁联系"];
    
    _kehuguanxipic = [[ZHPickView alloc] initPickviewWithArray:_kehuguanxi isHaveNavControler:NO];
    _kehuguanxipic.tag = 1004;
    _kehuguanxipic.delegate = self;

    _kehulaiyuan = @[@"广告引人",@"朋友介绍",@"渠道分配",@"其他"];
    
    _kehulaiyuanpic = [[ZHPickView alloc] initPickviewWithArray:_kehulaiyuan isHaveNavControler:NO];
    _kehulaiyuanpic.tag = 1005;
    _kehulaiyuanpic.delegate = self;

    _dailishuxin = @[@"新代理",@"回头客",@"忠实客户"];
    _dailishuxinpic = [[ZHPickView alloc] initPickviewWithArray:_dailishuxin isHaveNavControler:NO];
    _dailishuxinpic.tag = 1006;
    _dailishuxinpic.delegate = self;
    
    _chongshishiye = @[@"美容",@"健康",@"食品",@"服装",@"销售",@"后勤",@"文员"];
    _chongshishiyepic = [[ZHPickView alloc] initPickviewWithArray:_chongshishiye isHaveNavControler:NO];
    _chongshishiyepic.tag = 1007;
    _chongshishiyepic.delegate = self;

    _guimo = @[@"个人",@"公司",@"团队"];
    _guimopic = [[ZHPickView alloc] initPickviewWithArray:_guimo isHaveNavControler:NO];
    _guimopic.tag = 1008;
    _guimopic.delegate = self;

//     [_dataarray addObject:_guimo];
    _shifouguanzhu =@[@"是",@"否"];
    _shifouguanzhupic = [[ZHPickView alloc] initPickviewWithArray:_shifouguanzhu isHaveNavControler:NO];
    _shifouguanzhupic.tag = 1009;
    _shifouguanzhupic.delegate = self;

    
//    _custominfoview.birthTextField.delegate = self;
//    _custominfoview.birthTextField.enabled = NO;
 
//    _custominfoview.goumailitextfield.delegate = self;
//    _custominfoview.goumailitextfield.enabled = NO;
    
    
    [self setUpMainInterface];
}





-(void)toobarDonBtnHaveClick:(ZHPickView *)pickView resultString:(NSString *)resultString{
    
    
    NSInteger index = pickView.tag - 1000;
    switch (index) {
        case 0:
            _custominfoview.sexLabel.text = resultString;
            break;
        case 1:
            _custominfoview.customTypeLabel.text =resultString;
            break;
        case 2:
            _custominfoview.goumailitextfield.text = resultString;
          
            break;
        case 3:
            _custominfoview.baoyanLabel.text = resultString;
            break;
        case 4:
              _custominfoview.guanxiLabel.text = resultString;
            break;
        case 5:
            _custominfoview.laiyuanLabel.text = resultString;
            break;
        case 6:
            _custominfoview.suxinlabel.text = resultString;
            break;
        case 7:
            _custominfoview.zhiyeLabel.text = resultString;
            break;
        case 8:
            _custominfoview.goumolabel.text = resultString;
            break;
            
        case 9:
            _custominfoview.guanzhuLabel.text = resultString;
            break;
        case 10:
            _custominfoview.jiazhiLabel.text = resultString;
            break;
        case 11:
            _custominfoview.huazhuangpinLabel.text = resultString;
            break;
        case 12:
            _custominfoview.birthTextField.text = resultString;
            break;
            
        default:
            break;
    }
    
    
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

-(void)setUpMainInterface{
    
    self.view.backgroundColor = BSTColorFromRGB(0xffffff);
    
    _adviews = [MQadviews loadadviews];
    _adviews.bst_x = 0;
    _adviews.bst_width = BSTScreenW;
    _adviews.bst_height = 70 *Persion;
    _adviews.bst_y = NAVHEIGHT;
    [self.view addSubview:_adviews];
   
    _bgscrollview = [[UIScrollView alloc] init];
    
    _bgscrollview.bst_x=0;
    _bgscrollview.bst_y = NAVHEIGHT + 70 *Persion;
    _bgscrollview.bst_width = BSTScreenW;
    _bgscrollview.bst_height = BSTScreenH;
    
    MQCustomdetailinfoview *custominfoview = [MQCustomdetailinfoview mQCustomdetailinfoview];
    custominfoview.bst_x = 0;
    custominfoview.bst_y = 0;
    custominfoview.bst_width = BSTScreenW;
    custominfoview.bst_height = 1160;
    _custominfoview = custominfoview;
    
    
    [_custominfoview.sexbutton addTarget:self action:@selector(sexbuttonPressed) forControlEvents:UIControlEventTouchUpInside];
    [_custominfoview.customTypeButton addTarget:self action:@selector(customTypeButtonpressed) forControlEvents:UIControlEventTouchUpInside];
    [_custominfoview.adderbutton addTarget:self action:@selector(adderbuttonPressed) forControlEvents:UIControlEventTouchUpInside];
    [_custominfoview.guanxibutton addTarget:self action:@selector(guanxibuttonPressed) forControlEvents:UIControlEventTouchUpInside];
    [_custominfoview.laiyuanButton addTarget:self action:@selector(laiyuanButtonPressed) forControlEvents:UIControlEventTouchUpInside];
    [_custominfoview.suxinButton addTarget:self action:@selector(suxinButtonPressed) forControlEvents:UIControlEventTouchUpInside];
    [_custominfoview.zhiyebutton addTarget:self action:@selector(zhiyebuttonPressed) forControlEvents:UIControlEventTouchUpInside];
    [_custominfoview.jiazhibutton addTarget:self action:@selector(jiazhibuttonPressed) forControlEvents:UIControlEventTouchUpInside];
    [_custominfoview.baoyanButton addTarget:self action:@selector(baoyanButtonPressed) forControlEvents:UIControlEventTouchUpInside];
    [_custominfoview.guanzhubutton addTarget:self action:@selector(guanzhubuttonPressed) forControlEvents:UIControlEventTouchUpInside];
    [_custominfoview.guimobutton addTarget:self action:@selector(guimobuttonPressed) forControlEvents:UIControlEventTouchUpInside];
    [_custominfoview.huazhuangpinButton addTarget:self action:@selector(huazhuangpinButtonPressed) forControlEvents:UIControlEventTouchUpInside];
    
    [_custominfoview.birthdayButton addTarget:self action:@selector(birthdayButtonPresseds) forControlEvents:UIControlEventTouchUpInside];
    
    [_custominfoview.goumailibutton addTarget:self action:@selector(goumailibuttonPresseds) forControlEvents:UIControlEventTouchUpInside];
    
    _custominfoview.submitButton.layer.cornerRadius = 3.f;
    _custominfoview.submitButton.layer.masksToBounds = YES;
    [_custominfoview.submitButton addTarget:self action:@selector(submitButtonPressed:) forControlEvents:UIControlEventTouchUpInside];
    [_bgscrollview addSubview:custominfoview];
    [_bgscrollview setContentSize:CGSizeMake(BSTScreenW, 1160 + 70 * Persion)];
    [self.view addSubview:_bgscrollview];
    
    if (_type ==1) {
        _custominfoview.turenametextfiel.text = _custom.realName;
        _custominfoview.sexLabel.text = _custom.sex;
        _custominfoview.phoneNumberTextField.text = _custom.telephone;
        _custominfoview.adderLabel.text = [NSString stringWithFormat:@"%@%@%@",_custom.provinceName,_custom.cityName,_custom.areaName];
        
        _custominfoview.addersdetailTextFeild.text = _custom.addr;
        _custominfoview.customTypeLabel.text = _custom.leixin;
        _custominfoview.guanxiLabel.text  = _custom.guanxi;
        _custominfoview.birthTextField.text = _custom.birthday;
        _custominfoview.laiyuanLabel.text = _custom.laiyuan;
        _custominfoview.suxinlabel.text = _custom.shuxing;
        _custominfoview.zhiyeLabel.text = _custom.hangye;
        _custominfoview.jiazhiLabel.text = _custom.jiazhi;
        _custominfoview.baoyanLabel.text = _custom.baoyan;
        _custominfoview.huazhuangpinLabel.text = _custom.huaz;
        _custominfoview.guanzhuLabel.text = _custom.guanzhu;
        _custominfoview.goumolabel.text = _custom.guimo;
        [_custominfoview.submitButton setTitle:@"修改" forState:UIControlStateNormal];
    }else{
        [_custominfoview.submitButton setTitle:@"添加" forState:UIControlStateNormal];
    }
    
    [self.view bringSubviewToFront:_adviews];
    
    

}
-(void)birthdayButtonPresseds{
    [_birthdaypic show];
}
-(void)goumailibuttonPresseds{
    [_goumaipic show];
}

-(void)guimobuttonPressed{
    [_guimopic show];
}

-(void)guanzhubuttonPressed{
    [_shifouguanzhupic show];
}

-(void)huazhuangpinButtonPressed{
    [_huazhuangpingpic show];
}

-(void)baoyanButtonPressed{
    [_bapyangzhichupick show];
}

-(void)jiazhibuttonPressed{
    [_jianzhipic show];
}
-(void)zhiyebuttonPressed{
    [_chongshishiyepic show];
}

-(void)suxinButtonPressed{
    [_dailishuxinpic show];
}
-(void)guanxibuttonPressed{
    [_kehuguanxipic show];
}

-(void)laiyuanButtonPressed{
    [_kehulaiyuanpic show];
}

-(void)adderbuttonPressed{
    _adderssview.hidden = NO;
    [self.view bringSubviewToFront:_adderssview];
}


-(void)customTypeButtonpressed{
    [_kehulexingpick show];
}

-(void)sexbuttonPressed{
    [_sexpick show];
}

-(void)submitButtonPressed:(UIButton *)sender{
    
    
    if (_type == 1) {
        //修改
        [self update];
    }else{
        //添加
        [self add];
    }
    
}
-(void)add{
    
//    NSString 

    
    NSString *realname = _custominfoview.turenametextfiel.text;
    NSString *sex =_custominfoview.sexLabel.text;
    NSString *phone = _custominfoview.phoneNumberTextField.text;
    NSString *provincename = self.addarray[_provinceIndex][@"name"];
    NSString *city = self.addarray[_provinceIndex][@"list"][_cityIndex][@"name"];
    NSString *areaname = self.addarray[_provinceIndex][@"list"][_cityIndex][@"list"][_districtIndex][@"name"];
    NSString *addr = _custominfoview.addersdetailTextFeild.text;
    NSString *leixin = _custominfoview.customTypeLabel.text;
    NSString *guanxi = _custominfoview.guanxiLabel.text;
    NSString *birth = _custominfoview.birthTextField.text;
    NSString *laiyuan = _custominfoview.laiyuanLabel.text;
    NSString *shuxing = _custominfoview.suxinlabel.text;
    NSString *baoyan = _custominfoview.baoyanLabel.text;
    NSString *huazhuangping = _custominfoview.huazhuangpinLabel.text;
    NSString *hanegye = _custominfoview.zhiyeLabel.text;
    NSString *goumaili = _custominfoview.goumailitextfield.text;
    NSString *guimo = _custominfoview.goumolabel.text;
    NSString *guanzhu = _custominfoview.guanzhuLabel.text;
    
    if ([NSString isBlankString:realname]) {
        [iToastUtil displayMsg:@"请输入客户名字"];
        return;
    }
    if ([NSString isBlankString:sex]) {
        [iToastUtil displayMsg:@"请输入性别"];
        return;
    }
    if ([NSString isBlankString:realname]) {
        [iToastUtil displayMsg:@"请输入电话号码"];
        return;
    }
    if ([NSString isBlankString:provincename]) {
        [iToastUtil displayMsg:@"请选择收货地区"];
        return;
    }
    if ([NSString isBlankString:addr]) {
        [iToastUtil displayMsg:@"请输入详细地址"];
        return;
    }
    if ([NSString isBlankString:leixin]) {
        [iToastUtil displayMsg:@"请选择客户类型"];
        return;
    }
    if ([NSString isBlankString:guanxi]) {
        [iToastUtil displayMsg:@"请选择客户关系"];
        return;
    }
    if ([NSString isBlankString:laiyuan]) {
        [iToastUtil displayMsg:@"请选择客户来源"];
        return;
    }
    if ([NSString isBlankString:shuxing]) {
        [iToastUtil displayMsg:@"请选择客户属性"];
        return;
    }
    if ([NSString isBlankString:baoyan]) {
        [iToastUtil displayMsg:@"请选择保养支出"];
        return;
    }
    if ([NSString isBlankString:huazhuangping]) {
        [iToastUtil displayMsg:@"请选择化妆品支持"];
        return;
    }
    if ([NSString isBlankString:guimo]) {
        [iToastUtil displayMsg:@"请选择规模"];
        return;
    }
    if ([NSString isBlankString:guanzhu]) {
        [iToastUtil displayMsg:@"请选择是否关注"];
        return;
    }

    
    MQBaseUserInfoModel *userinfo = [MQBaseUserInfoModel shareInstant];
    [userinfo loadUserinfoFromSadeBox];
    NSMutableDictionary *param = [NSMutableDictionary dictionary];
    [param setValue:userinfo.userId forKey:@"userId"];
    
    
    [param setValue:sex forKey:@"sex"];
    [param setValue:birth forKey:@"birthday"];
    [param setValue:realname forKey:@"realName"];
    [param setValue:phone forKey:@"telephone"];
    [param setValue:provincename forKey:@"provinceName"];
    [param setValue:city forKey:@"cityName"];
    [param setValue:areaname forKey:@"areaName"];
    [param setValue:addr forKey:@"addr"];
    [param setValue:leixin forKey:@"leixin"];
    [param setValue:guanxi forKey:@"guanxi"];
    [param setValue:laiyuan forKey:@"laiyuan"];
    [param setValue:shuxing forKey:@"shuxing"];
    [param setValue:hanegye forKey:@"hangye"];
    [param setValue:guimo forKey:@"guimo"];
    [param setValue:guanzhu forKey:@"guanzhu"];
    [param setValue:goumaili forKey:@"jiazhi"];
    [param setValue:goumaili forKey:@"goumaili"];
    [param setValue:baoyan forKey:@"baoyan"];
    
    [param setValue:huazhuangping forKey:@"huaz"];
    

    [MQRequestTools POSTWithMethod:customer_save params:param success:^(id json) {
        
        [self.navigationController popViewControllerAnimated:YES];
    } failure:^(NSError *error) {
        
    }];
    
    
}
-(void)update{
    
    NSString *realname = _custominfoview.turenametextfiel.text;
    NSString *sex =_custominfoview.sexLabel.text;
    NSString *phone = _custominfoview.phoneNumberTextField.text;
    NSString *provincename = self.addarray[_provinceIndex][@"name"];
    NSString *city = self.addarray[_provinceIndex][@"list"][_cityIndex][@"name"];
    NSString *areaname = self.addarray[_provinceIndex][@"list"][_cityIndex][@"list"][_districtIndex][@"name"];
    NSString *addr = _custominfoview.addersdetailTextFeild.text;
    NSString *leixin = _custominfoview.customTypeLabel.text;
    NSString *guanxi = _custominfoview.guanxiLabel.text;
    NSString *birth = _custominfoview.birthTextField.text;
    NSString *laiyuan = _custominfoview.laiyuanLabel.text;
    NSString *shuxing = _custominfoview.suxinlabel.text;
    NSString *baoyan = _custominfoview.baoyanLabel.text;
    NSString *huazhuangping = _custominfoview.huazhuangpinLabel.text;
    NSString *hanegye = _custominfoview.zhiyeLabel.text;
    NSString *goumaili = _custominfoview.goumailitextfield.text;
    NSString *guimo = _custominfoview.goumolabel.text;
    NSString *guanzhu = _custominfoview.guanzhuLabel.text;
    
    if ([NSString isBlankString:realname]) {
        [iToastUtil displayMsg:@"请输入客户名字"];
        return;
    }
    if ([NSString isBlankString:sex]) {
        [iToastUtil displayMsg:@"请输入性别"];
        return;
    }
    if ([NSString isBlankString:realname]) {
        [iToastUtil displayMsg:@"请输入电话号码"];
        return;
    }
    if ([NSString isBlankString:provincename]) {
        [iToastUtil displayMsg:@"请选择收货地区"];
        return;
    }
    if ([NSString isBlankString:addr]) {
        [iToastUtil displayMsg:@"请输入详细地址"];
        return;
    }
    if ([NSString isBlankString:leixin]) {
        [iToastUtil displayMsg:@"请选择客户类型"];
        return;
    }
    if ([NSString isBlankString:guanxi]) {
        [iToastUtil displayMsg:@"请选择客户关系"];
        return;
    }
    if ([NSString isBlankString:laiyuan]) {
        [iToastUtil displayMsg:@"请选择客户来源"];
        return;
    }
    if ([NSString isBlankString:shuxing]) {
        [iToastUtil displayMsg:@"请选择客户属性"];
        return;
    }
    if ([NSString isBlankString:baoyan]) {
        [iToastUtil displayMsg:@"请选择保养支出"];
        return;
    }
    if ([NSString isBlankString:huazhuangping]) {
        [iToastUtil displayMsg:@"请选择化妆品支持"];
        return;
    }
    if ([NSString isBlankString:guimo]) {
        [iToastUtil displayMsg:@"请选择规模"];
        return;
    }
    if ([NSString isBlankString:guanzhu]) {
        [iToastUtil displayMsg:@"请选择是否关注"];
        return;
    }

    
    MQBaseUserInfoModel *userinfo = [MQBaseUserInfoModel shareInstant];
    [userinfo loadUserinfoFromSadeBox];
    NSMutableDictionary *param = [NSMutableDictionary dictionary];
    [param setValue:userinfo.userId forKey:@"userId"];
    
    
    [param setValue:sex forKey:@"sex"];
    [param setValue:birth forKey:@"birthday"];
    [param setValue:realname forKey:@"realName"];
    [param setValue:phone forKey:@"telephone"];
    [param setValue:provincename forKey:@"provinceName"];
    [param setValue:city forKey:@"cityName"];
    [param setValue:areaname forKey:@"areaName"];
    [param setValue:addr forKey:@"addr"];
    [param setValue:leixin forKey:@"leixin"];
    [param setValue:guanxi forKey:@"guanxi"];
    [param setValue:laiyuan forKey:@"laiyuan"];
    [param setValue:shuxing forKey:@"shuxing"];
    [param setValue:hanegye forKey:@"hangye"];
    [param setValue:guimo forKey:@"guimo"];
    [param setValue:guanzhu forKey:@"guanzhu"];
    [param setValue:goumaili forKey:@"jiazhi"];
    [param setValue:goumaili forKey:@"goumaili"];
    [param setValue:baoyan forKey:@"baoyan"];
    
    [param setValue:huazhuangping forKey:@"huaz"];
    [param setValue:_custom.ID forKey:@"id"];
    [param setValue:_custom.agentId forKey:@"agentId"];
    
    
    
    [MQRequestTools POSTWithMethod:customer_update params:param success:^(id json) {
        NSLog(@"%@",json);
        [self.navigationController popViewControllerAnimated:YES];
    } failure:^(NSError *error) {
//        [iToastUtil displayMsgByLongtime:]
    }];
}



@end
